package com.bdzl.biz.controller;

import com.bdzl.biz.service.AgentRelBankcardService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.loan.AgentRelBankcardDO;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 经销商与银行卡关系表
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-11 15:23:42
 */

@Controller
@RequestMapping("/bdzl/agentRelBankcard")
public class AgentRelBankcardController extends BaseController {
	@Autowired
	private AgentRelBankcardService agentRelBankcardService;

	@GetMapping()
	String AgentRelBankcard(){
	    return "bdzl/agentRelBankcard/agentRelBankcard";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<AgentRelBankcardDO> agentRelBankcardList = agentRelBankcardService.list(query);
		int total = agentRelBankcardService.count(query);
		PageUtils pageUtils = new PageUtils(agentRelBankcardList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/agentRelBankcard/add";
	}

	@GetMapping("/edit/{arbId}")
	String edit(@PathVariable("arbId") Integer arbId,Model model){
		AgentRelBankcardDO agentRelBankcard = agentRelBankcardService.get(arbId);
		model.addAttribute("agentRelBankcard", agentRelBankcard);
	    return "bdzl/agentRelBankcard/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( AgentRelBankcardDO agentRelBankcard){
		if(agentRelBankcardService.save(agentRelBankcard)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( AgentRelBankcardDO agentRelBankcard){
		agentRelBankcardService.update(agentRelBankcard);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer arbId){
		if(agentRelBankcardService.remove(arbId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] arbIds){
		agentRelBankcardService.batchRemove(arbIds);
		return R.ok();
	}

}
